package view.backing.Utils.Validator;

import java.util.Hashtable;

import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.validator.Validator;
import javax.faces.validator.ValidatorException;

import javax.naming.Context;

import javax.naming.InitialContext;
import javax.naming.NamingException;

public class EnteroPositivoValidator implements Validator {
    
    @Override 
    public void validate(FacesContext facesContext, UIComponent uiComponent, Object object) {
            String cantidad = object.toString();
            int iCantidad = 0;
            try{
                iCantidad = Integer.parseInt(cantidad);
            }catch(Exception e){
                FacesMessage fm = new FacesMessage("Inserte solo numeros.");
                throw new ValidatorException(fm);
            }
            if (iCantidad < 1) {
                FacesMessage fm = new FacesMessage("Inserte un numero entero mayor a 0.");
                throw new ValidatorException(fm);
            }
        }
}
 